<?php
namespace app\model;

use think\Model;

use think\facade\Db;

class DiyModel extends Model
{
    protected $table   = 'sh_diy';
    
    
    public static function single( $diy_id ){

        // global $_W;

        $uniacid = current_uni_account();
        $sql = 'select * from sh_diy where uniacid=' . $uniacid . ' and id=' . $diy_id ;
        // return pdo_fetch( $sql );
        return Db::query( $sql )[0];

    }

    public static function edit( $diy_id, $data ){

        $sql = 'update sh_diy set '
            . " title='" . $data['title'] . "',"
            . " diy='" . $data['diy'] . "',"
            . " updated_at='" . $data['updated_at'] . "' "
            . " where id= " . $diy_id;

        // return pdo_query( $sql );
        return Db::execute( $sql );
    }

    //tp6兼容性： 改名为 create->create2
    public static function create2( $data ){

        $sql = "insert into sh_diy set "
            . " title='" . $data['title'] . "',"
            . " diy='" . $data['diy'] . "',"
            . " uniacid='" . $data['uniacid'] . "',"
            . " updated_at='" . $data['updated_at'] . "',"
            . " created_at='" . $data['created_at'] . "';"
        ;
        // return pdo_query( $sql );
        return Db::execute( $sql );
    }

    //tp6兼容性： 改名为 delete->delete2
    public static function delete2( $diy_id ){

        $sql = 'delete from sh_diy '
            . " where id= " . $diy_id;
        // return pdo_query( $sql );
        return Db::execute( $sql );
    }
}